<?php
namespace app\controller;

use app\BaseController;
use app\model\User;
use think\facade\Session;
use think\facade\View;

class Index extends BaseController
{
    public function index()
    {
        return View::fetch('index');
    }

    public function login()
    {
        $user = $this->request->post('username');
        $pass = $this->request->post('password');
        $users = User::where(['username'=>$user,"password"=>userPass($pass)])->find();
        if(!$users){
            return $this->error("账户不存在或密码错误");
        }
        Session::clear();
        Session::set('uid',$users['id']);
        Session::set('user',$users['username']);
        Session::set('name',$users['name']);
        return redirect(url('/data/index'));


    }
    public function logout(){

        Session::clear();

        return redirect(url('/index/index'));
    }
}
